#!/usr/bin/env python

##copyright 2014 Sebastian Stetter
##This file is part of the Lemonade Small Business Suite project and released under GPL v2
##http://lemonade.sebastianstetter.de


from camelot.core.conf import settings, SimpleSettings
import logging
logging.basicConfig( level = logging.ERROR )
logger = logging.getLogger( 'main' )

# begin custom settings
class MySettings( SimpleSettings ):

    # add an ENGINE or a CAMELOT_MEDIA_ROOT method here to connect
    # to another database or change the location where files are stored
    #
    # def ENGINE( self ):
    #     from sqlalchemy import create_engine
    #     return create_engine( 'postgresql://user:passwd@127.0.0.1/database' )
    
    
    def setup_model( self ):
        """This function will be called at application startup, it is used to 
        setup the model"""
        from camelot.core.sql import metadata
        from camelot.core.orm import setup_all
        metadata.bind = self.ENGINE()
        import camelot.model.authentication
        import camelot.model.i18n
        import camelot.model.memento
        from lemonade.fixtures import update_fixtures

        setup_all(create_tables=True)
        # Load sample data with the fixure mechanism
        update_fixtures()
        metadata.create_all()

my_settings = MySettings( 'Sebastian Stetter', 'Lemonade Small Business Suite' ) 
settings.append( my_settings )

# end custom settings

def start_application():
    from camelot.view.main import main
    from lemonade.application_admin import MyApplicationAdmin
    main(MyApplicationAdmin())

if __name__ == '__main__':
    start_application()

    
